home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-vallli.adb < prev    next >
Text File  |  1996-01-30  |  4KB  |  94 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                       S Y S T E M . V A L _ L L I                        --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.6 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Unsigned_Types; use System.Unsigned_Types;
  27. with System.Val_LLU;        use System.Val_LLU;
  28. with System.Val_Util;       use System.Val_Util;
  29.  
  30. package body System.Val_LLI is
  31.  
  32.    ---------------------------
  33.    -- Scn_Long_Long_Integer --
  34.    ---------------------------
  35.  
  36.    function Scan_Long_Long_Integer
  37.      (Str  : String;
  38.       Ptr  : access Positive'Base;
  39.       Max  : Positive'Base)
  40.       return Long_Long_Integer
  41.    is
  42.       Uval : Long_Long_Unsigned;
  43.       --  Unsigned result
  44.  
  45.       Minus : Boolean := False;
  46.       --  Set to True if minus sign is present, otherwise to False
  47.  
  48.       Start : Positive;
  49.       --  Saves location of first non-blank (not used in this case)
  50.  
  51.    begin
  52.       Scan_Sign (Str, Ptr, Max, Minus, Start);
  53.       Uval := Scan_Long_Long_Unsigned (Str, Ptr, Max);
  54.  
  55.       --  Deal with overflow cases, and also with maximum negative number
  56.  
  57.       if Uval > Long_Long_Unsigned (Long_Long_Integer'Last) then
  58.          if Minus
  59.            and then Uval = Long_Long_Unsigned (-(Long_Long_Integer'First)) then
  60.             return Long_Long_Integer'First;
  61.          else
  62.             raise Constraint_Error;
  63.          end if;
  64.  
  65.       --  Negative values
  66.  
  67.       elsif Minus then
  68.          return -(Long_Long_Integer (Uval));
  69.  
  70.       --  Positive values
  71.  
  72.       else
  73.          return Long_Long_Integer (Uval);
  74.       end if;
  75.  
  76.    end Scan_Long_Long_Integer;
  77.  
  78.    -----------------------------
  79.    -- Value_Long_Long_Integer --
  80.    -----------------------------
  81.  
  82.    function Value_Long_Long_Integer (Str : String) return Long_Long_Integer is
  83.       V : Long_Long_Integer;
  84.       P : aliased Natural := Str'First;
  85.  
  86.    begin
  87.       V := Scan_Long_Long_Integer (Str, P'Access, Str'Last);
  88.       Scan_Trailing_Blanks (Str, P);
  89.       return V;
  90.  
  91.    end Value_Long_Long_Integer;
  92.  
  93. end System.Val_LLI;
  94.